package cqrtplm.controller;

import com.ty.basic.entity.enumeration.EnumerationDefDO;
import com.ty.basic.response.ResponseResult;
import cqrtplm.constant.RouteConstant;
import cqrtplm.dto.CreateChildEnumDTO;
import cqrtplm.service.TyEnumerationdefService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.math.BigInteger;

@RestController
@RequestMapping(RouteConstant.ENUM + "v1")
@Slf4j
public class RTEnumController {

    @Resource
    private TyEnumerationdefService tyEnumerationdefService;

    @RequestMapping("/importEnumList")
    public void importEnumList(MultipartFile file) {
        tyEnumerationdefService.batchImportEnum(file);
    }

    @RequestMapping("/getTYEnumByName")
    @ResponseBody
    public ResponseResult getTYEnumByName(String name, String description) {
        return ResponseResult.success(tyEnumerationdefService.selectEnumByName(name, description));
    }

    @RequestMapping("/createChildEnum")
    public ResponseResult<EnumerationDefDO> createChildEnum(@RequestBody CreateChildEnumDTO dto) {
        return ResponseResult.success(tyEnumerationdefService.createChildEnum(dto));
    }

    @GetMapping("/getTYEnumByOid")
    public ResponseResult<EnumerationDefDO> getTYEnumByOid(String defoid) {
        return ResponseResult.success(tyEnumerationdefService.getTYEnumByOid(defoid));
    }

    @GetMapping("/checkAttrIfBindingEnum")
    @ApiOperation(value = "检查属性是否绑定枚举")
    public ResponseResult<Void> checkAttrIfBindingEnum(@Param("classOid") String classOid, @Param("classType") String classType){
        tyEnumerationdefService.checkAttrIfBindingEnum(new BigInteger(classOid), classType);
        return ResponseResult.success();
    }
}
